<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<jsp:include page="/WEB-INF/common/head.jsp" flush="true" />
 <div class="easyui-panel addPage" data-options="fit:true,border:false">
    <form id="ff" method="post" class="easyui-form" data-options="novalidate:true">
        <table class="table1">
      
            <tr>
           		<th><span>菜单名称：</span></th>
               	<td> 
            		<div class="wrap_input">
            		<input name="id" type="hidden" value="${sysRes.id}"/>
            		<input class="easyui-textbox" data-options="fit:true, required:true" type="text" value="${sysRes.name}" name="name"></input></div>
           		</td>
           	</tr>
        	<tr>	
           		<th><span>菜单地址：</span></th>
               	<td>
            		<div class="wrap_input"><input class="easyui-textbox" type="text" name="url"  value="${sysRes.url}" data-options="fit:true, required:true"></input></div>
           		</td>
            </tr>
        	<tr>
           		<th><span>上级菜单：</span></th>
               	<td>
            		<div class="wrap_input">
            		<input id="pname" class="easyui-textbox" type="text"  value="${sysRes.pid}" name="pname" data-options="fit:true, required:true"></input></div>
           		</td>
           	</tr>
        	<tr>	
           		<th><span>图标：</span></th>
               	<td>
            		<div class="wrap_input"><input type="text" name="iconCls" value="${sysRes.iconCls}"   onclick='top.window.openPopup(this, "请选择图标", "${context_path}/sys/res/iconsPage", {width: 540, height: 400})' ></input></div>
           		</td>
            </tr>
            <tr>
           		<th><span>顺序：</span></th>
               	<td>
            		<div class="wrap_input"><input class="easyui-textbox" type="text" value="${sysRes.seq}" name="seq" data-options="fit:true"></input></div>
           		</td>
            </tr>
        </table>
    </form>
</div>
<script>
$(function() {
	//上级菜单
	$.post("${context_path}/sys/res/getAllMenu", function(data) {
		var menulist = [];
		$.each(data, function(i, item) {
			menulist.push({
				id: item.id,
				text: item.name,
				attributes: item.url, 
				parent_id: item.pid,
				iconCls: item.icon
			});
		});
		
		for(var i = 0; i < menulist.length; i++) {
			var children = menulist[i].children || [];
			for(var j = 0; j < menulist.length; j++) {
				if(menulist[j].parent_id == menulist[i].id) {
					children.push(menulist[j]);
				}
			}
			menulist[i].children = children;
		}
		
		var treeData = [{id:"0", text:'一级菜单', iconCls:'glyphicon-asterisk'}];
		$.each(menulist, function(i, item) {
			if(item.parent_id == 0) {
				treeData.push(item);
			}
		});
		$("#pname").combotree({
			data: treeData
		});
	});
	
/* 	$(document).click(function() {
		var target = event.target || event.srcElement;
		if($(target).attr("name") != 'icon') {
			top.window.closePopup();
		}
	}); */
});

top.window.subPage.save = save;
function save(successFunc) {
	if($("#ff").form('enableValidation').form('validate')) {
		$.post("${context_path}/sys/res/saveRes", getParam(), function(data) {
			if(successFunc) {
				successFunc();
			}
			top.window.closeWindow();
			top.window.subPage.loadCurrDatagrid();
		});
	}
}
function getParam() {
	var param = {
   	    "name": $(":input[name='name']").val(), 
  	    "url": $(":input[name='url']").val(), 
  	    "pid":  $(":input[name='pname']").val(), 
  	    "iconCls": $(":input[name='iconCls']").val(), 
   	    "seq": $(":input[name='seq']").val(),
   	    "id": $(":input[name='id']").val()
	}
	for(key in param) {
		if(!param[key]) {
			delete param[key];
		}
	}
	return param;
}
</script>
  <jsp:include page="/WEB-INF/common/dialogWindow.jsp" flush="true" />
   <jsp:include page="/WEB-INF/common/foot.jsp" flush="true" />